//package com.moli.iov.task.service.impl;
//
//import com.moli.iov.his.model.po.ReportSelledOnline;
//import com.moli.iov.his.model.po.ReportStoreSelledOnline;
//import com.moli.iov.his.model.po.ReportStoreTotalOnline;
//import com.moli.iov.his.model.po.ReportTotalOnline;
//import com.moli.iov.his.service.IReportSelledOnlineService;
//import com.moli.iov.his.service.IReportStoreSelledOnlineService;
//import com.moli.iov.his.service.IReportStoreTotalOnlineService;
//import com.moli.iov.his.service.IReportTotalOnlineService;
//import com.moli.iov.rest.RestResponse;
//import com.moli.iov.task.service.IVehicleStatisticsService;
//import com.moli.iov.task.service.IVehicleStoreStatisticsService;
//import com.moli.iov.util.DateUtil;
//import com.moli.iov.vehicle.model.dto.req.VehicleBaseQueryVinListReqDto;
//import com.moli.iov.vehicle.service.IVehicleBaseService;
//import com.moli.iov.vehicle.service.IVehicleTboxService;
//import com.xxl.job.core.log.XxlJobLogger;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//import java.math.BigDecimal;
//import java.math.RoundingMode;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//import java.util.Map;
//
///**
// * @author fudh
// * @ClassNmme VehicleStatisticsService
// * @date 2019/2/19 13:27
// * @Description: TODO
// */
//@Slf4j
//@Service("vehicleStoreStatisticsService")
//public class VehicleStoreStatisticsServiceImpl implements IVehicleStoreStatisticsService {
//
//    @Resource
//    private IVehicleTboxService iVehicleTboxService;
//
//    @Resource
//    private IReportStoreTotalOnlineService reportStoreTotalOnlineService;
//
//    @Resource
//    public IVehicleBaseService vehicleBaseService;
//
//    @Resource
//    private IReportStoreSelledOnlineService reportStoreSelledOnlineService;
//
//    @Override
//    public boolean vehicleOnlineStatistics(Map<String,List<String>> storeMap) {
//        XxlJobLogger.log("开始统计在网车辆上线率.....");
//        //门店、中转库code集合
//       List<Striang>storeCodes= new ArrayList<>(0);
//       storeMap.forEach((code,vins)->{ if(vins==null){return ;}storeCodes.add(code);});
//       //获取各门店、中转库中存在的vin集合;
//        RestResponse<Map<String, List<String>>> mapRestResponse = vehicleBaseService.queryVehicleByStorageCode(storeCodes);
//        Map<String, List<String>> mapData = mapRestResponse.getData();
//        storeMap.forEach((storeCode,vinOnLins)->{
//            if (vinOnLins == null ) {
//                return;
//            }
//            try {
//                //2、查询在网车辆总数
//                long totalVinCount;
//                try {
//                    if (mapData != null) {
//                        totalVinCount = (long) mapData.get(storeCode).size();
//                    } else {
//                        XxlJobLogger.log("查询在网的vin总数失败");
//                        log.error("查询在网的vin总数失败");
//                        totalVinCount = 0;
//                    }
//                } catch (Exception e) {
//                    XxlJobLogger.log("查询在网的vin总数失败");
//                    log.error(e.getMessage(), e);
//                    totalVinCount = 0;
//                }
//                long onlineVehicleCount = vinOnLins.size();
//                XxlJobLogger.log("在线车辆数：" + onlineVehicleCount + "\t在网总数：" + totalVinCount);
//                BigDecimal onLineRate;
//                if (totalVinCount == 0 || onlineVehicleCount == 0) {
//                    onLineRate = BigDecimal.valueOf(0);
//                } else {
//                    BigDecimal decimal = BigDecimal.valueOf(onlineVehicleCount * 100);
//                    BigDecimal decimal1 = BigDecimal.valueOf(totalVinCount);
//                    //3、计算昨天的在线率
//                    onLineRate = decimal.divide(decimal1, 1, RoundingMode.HALF_UP);
//                }
//                XxlJobLogger.log("在网车辆上线率:" + onLineRate.doubleValue());
//                //4、入库在网数据
//                ReportStoreTotalOnline reportStoreTotalOnline = new ReportStoreTotalOnline(totalVinCount, onlineVehicleCount, onLineRate,storeCode);
//                reportStoreTotalOnline.setStatTime(DateUtil.subDay(new Date(), 1));
//                reportStoreTotalOnlineService.saveReportTotalOnline(reportStoreTotalOnline);
//            } catch (Exception e) {
//                log.error(e.getMessage(),e);
//                XxlJobLogger.log("统计在网车辆上线率出错！");
//
//            }
//
//        });
//        return true;
//    }
//}
